package com.sanpu.kxe.business.main.view;

import android.content.Context;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.sanpu.kxe.R;
import com.sanpu.kxe.base.BaseTitleActivity;
import com.sanpu.kxe.business.main.bean.ReferrerOutput;
import com.sanpu.kxe.business.main.contract.MyReferrerContract;
import com.sanpu.kxe.business.main.presenter.MyReferrerPresenter;
import com.sanpu.kxe.common.cache.CacheManage;
import com.sanpu.kxe.common.cache.CacheModel;
import com.sanpu.kxe.common.interfaces.UrlConstants;
import com.sanpu.kxe.jump.imageloader.JKImageLoader;
import com.sanpu.kxe.rxservice.RequestMap;

import butterknife.Bind;

/**
 * Description：我的推荐人
 * Created by 薛勇军 on 2018/7/10.
 */

public class MyReferrerActivity extends BaseTitleActivity implements MyReferrerContract.View {

    @Bind(R.id.referName)
    TextView referName;
    @Bind(R.id.referTelNum)
    TextView referTelNum;
    @Bind(R.id.referWtNum)
    TextView referWtNum;
    @Bind(R.id.referWtCode)
    ImageView referWtCode;

    private MyReferrerContract.Presenter mPresenter;

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_my_referrer;
    }

    @Override
    protected void initView() {
        super.initView();
        commonTitle.setTitle("我的推荐人");
        showView();
        mPresenter = new MyReferrerPresenter(this);
        mPresenter.getReferrerUserInfo();
    }

    @Override
    public void showView() {
        ReferrerOutput output = CacheManage.getInstance().getCache(CacheModel.REFERRER_INFO);
        if (output != null) {
            if (!TextUtils.isEmpty(output.getRename())) {
                referName.setText(output.getRename());
            }
            if (!TextUtils.isEmpty(output.getTelNum())) {
                referTelNum.setText(output.getTelNum());
            }
            if (!TextUtils.isEmpty(output.getWxChatId())) {
                referWtNum.setText(output.getWxChatId());
            }
            if (!TextUtils.isEmpty(output.getWxQrcodeImg())) {
                String imgUrl = UrlConstants.getBaseUrl() + output.getWxQrcodeImg() + RequestMap.sessionIdReqStr();
                JKImageLoader.getInstance().displayImage(mContext, imgUrl, referWtCode);
            }

        }
    }

    @Override
    protected boolean hasBindEventBus() {
        return false;
    }

    @Override
    public void setPresenter(MyReferrerContract.Presenter presenter) {
        this.mPresenter = presenter;
    }

    @Override
    public Context getContext() {
        return this;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.onDestroyPresenter();
            mPresenter = null;
        }
    }
}
